import requests

from spider.core.BaseSpider import BaseSpider

class WxworkSpider(BaseSpider):
    def __init__(self,cookie):
        self.http=requests.session()
        self.cookie = cookie
        self.headers={
  'authority': 'work.weixin.qq.com',
  'accept': 'application/json, text/javascript, */*; q=0.01',
  'x-requested-with': 'XMLHttpRequest',
  'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36',
  'content-type': 'application/x-www-form-urlencoded',
  'sec-fetch-site': 'same-origin',
  'sec-fetch-mode': 'cors',
  'sec-fetch-dest': 'empty',
  'referer': 'https://work.weixin.qq.com/wework_admin/frame',
  'accept-language': 'zh-CN,zh;q=0.9',
  'cookie': cookie,
}

    def getGroupChatList(self):
        url = "https://work.weixin.qq.com/wework_admin/customer/getGroupChatList?lang=zh_CN&f=json&ajax=1&timeZoneInfo%5Bzone_offset%5D=-8&random=0.44978471934550335&off_set=10&limit=10&create_ts_begin=1617292800&create_ts_end=1622593426&page=2&accurate_keywords=&_d2st=a1909535"
        payload = {}
        response = requests.request("GET", url, headers=self.headers, data=payload)
        json1 = response.json()
        print(json1["data"]["datalist"][0])

    def getGroupChatListByPage(self,create_ts_begin,create_ts_end,page):
        url = "https://work.weixin.qq.com/wework_admin/customer/getGroupChatList?lang=zh_CN&f=json&ajax=1&timeZoneInfo%5Bzone_offset%5D=-8&random=0.44978471934550335&off_set=10&limit=10&create_ts_begin=1617292800&create_ts_end=1622593426&page=2&accurate_keywords=&_d2st=a1909535"
        payload = {}
        response = requests.request("GET", url, headers=self.headers, data=payload)
        json1 = response.json()
        print(json1["data"]["datalist"][0])


if __name__ == '__main__':
    cookie='RK=GGi4TFofXv; ptcz=ed7596349d9abdb7acd2a08579b152f7bea7e8a2b010b9482ca8e174bbcbea4b; pgv_pvid=4590865652; wwrtx.c_gdpr=0; worknote_upgradeFlag1688851379198264=; wwrtx.i18n_lan=zh; qq_openid=35936AD63D30336DB3F1552AFD0B2B72; qq_access_token=AE896C4B3FF4EB81AED38A04D02DD4E0; qq_client_id=101487368; pac_uid=3_35936AD63D30336DB3F1552AFD0B2B72; xw_main_login=qq; tvfe_boss_uuid=c4303f2569135296; pt_sms_phone=189******53; Hm_lvt_9364e629af24cb52acc78b43e8c9f77d=1620187293,1620523423; iip=0; ptui_loginuin=179049114; wwrtx.ref=direct; wwrtx.refid=01414254; ww_rtkey=7bjsu9t; wwrtx.vst=kXZrEgSo-9G57t18wCyh8Nh7UlqrPGCWlb5BjA8pT_jc1MltXOFYUkjgv7mq8qnopKtx4pH-HcXv0PPj2f3DR7f0bUgJfjxZ-Pj28Up6uJyV46yMPbPOY1ox81gPh66kjhpQyYRuTVYTC7WZy8ofGQ4EOF-VWmL3MhTxI-L-uB5hLQxeqqBeNnurg8uxSMsjqLTLgRmgx6Rwux7GaZD2Jz0ItRSk_akGJHJp5Pw0XxhncrWYbnXXkyw0FrSzQWXtLqx3ejzTSQ4E1NZHAFKYow; wwrtx.d2st=a1909535; wwrtx.sid=8tV4XZLZFAtR-PfSlLv-3THA-N1fquwT4hlYYYLx3e8TpVz_a-D7Wue5bKDsq2Ox; wwrtx.ltype=1; wwrtx.vid=1688851379198264; wxpay.corpid=1970325131445067; wxpay.vid=1688851379198264; wwrtx.cs_ind=; wwrtx.i18n_lan=zh'
    wxworkSpider=WxworkSpider(cookie)
    wxworkSpider.getGroupChatList()